package com.uchengwang.ui.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;

import com.uchengwang.functions.http.listener.OnHttpResultSingleListener;

import cn.bingoogolapple.qrcode.core.BGAQRCodeUtil;
import cn.bingoogolapple.qrcode.zxing.QRCodeEncoder;

/**
 * Created by U城网 on 2018/1/31.
 */

public class QRCodeUtils {
    private QRCodeUtils (){}

    private static QRCodeUtils utils;

    public static QRCodeUtils getUtils() {
        if (utils ==null){
            utils = new QRCodeUtils();
        }
        return utils;
    }

    /**
     *生成二维码
     * */
    public void createQRCode(final Context context, final String content, final OnHttpResultSingleListener<Bitmap> listener){
        ExecutorsUtils.getUtils().createSingleThread().execute(new Runnable() {
            @Override
            public void run() {
                Bitmap b = QRCodeEncoder.syncEncodeQRCode(content, BGAQRCodeUtil.dp2px(context, 150), Color.parseColor("#000000"));
                listener.onResult(0, null, b);
            }
        });
    }

}
